
Page({

  /**
   * 页面的初始数据
   */
  data: {

    people: '',
    title:"",
    period: '',
    packinfo:"",
    timecont:"",
    time:false,
    mask: false,
    select: true,
    crowd: [
      { title: "0-6岁小孩",},
      { title: "青年人",},
      { title: "中年人",},
      { title: "孕妇",},
      { title: "老年人",},
    ],
    timelist:[
      {time:'2018.01.01-2019.01.01'},
      { time: '2019.01.01-2020.01.01' },
      { time: '2020.01.01-2021.01.01' },
      { time: '2021.01.01-2022.01.01' },
      { time: '2022.01.01-2023.01.01' },
    ],
    timeindex:0,
    current: 0,
    attendSuccessImg:""
  },
  whether: function (e) {
    this.setData({
      select: e.detail.value
    })
  },
  //获取标题
  title:function(e){
    this.setData({
      title:e.detail.value
    })
  },
  //服务包介绍
  packinfo:function(e){
    this.setData({
      packinfo:e.detail.value
    })
  },
  //服务包价格
  packprice:function(e){
    
    this.setData({
      packprice:e.detail.value
    })
  },
  //选择人群弹出遮罩
  choosecrowd: function () {
    this.setData({
      mask: !this.data.mask
    })
  },
  //选择人群并关闭遮罩
  crowdbtn: function (e) {
    var id = e.currentTarget.dataset.id
    var crowd = this.data.crowd
    this.setData({
      current: id,
      people: crowd[id].title,
      mask: !this.data.mask
    })
  },
  switchTime:function(){
    this.setData({
      time:!this.data.time
    })
  },
  timebtn:function(e){
    var id = e.currentTarget.dataset.id
    var timelist = this.data.timelist
    this.setData({
      time:!this.data.time,
      timeindex:id,
      timecont:timelist[id].time
    })
  },
  takePictures: function () {
    var that = this;
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths;
        that.setData({
          attendSuccessImg: tempFilePaths[0]
        });
        // 上传图片
        //判断机型
        var model = "";
        wx.getSystemInfo({
          success: function (res) {
            var that = this;
            model = res.model;
          }
        })
        if (model.indexOf("iPhone") <= 0) {
          // that.uploadFileOpt(that.data.attendSuccessImg);
          console.log(111111)
        } else {
          drawCanvas();

        }
        // 缩放图片
        function drawCanvas() {
          const ctx = wx.createCanvasContext('attendCanvasId');
          ctx.drawImage(tempFilePaths[0], 0, 0, 94, 96);
          ctx.draw();
          that.prodImageOpt();
        }
      }
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})